#include<stdio.h>
#include<stdlib.h>
typedef struct {
    int length,diameter,number;
} PIPE;
void input(PIPE* p) {
    scanf("%d%d%d",&p->length,&p->diameter,&p->number);
}
int inc(const void*a,const void*b){
    PIPE*pa=(PIPE*)a,*pb=(PIPE*)b;
    int dLen = pb->length - pa->length;
    if(dLen)return dLen;
    int dDia= pa->diameter - pb->diameter;
    if(dDia) return dDia;
    return pb->number - pa->number;
}
PIPE pipes[1000];
int main() {
    freopen("nyist263.in","r",stdin);
    int n,i,m;
    for(scanf("%d",&n); n--;) {
        scanf("%d",&m);
        for(i=0; i<m; i++)input(pipes+i);
        qsort(pipes,m,sizeof(PIPE),inc);
        printf("%d\n",pipes[0].number);
    }
    return 0;
}

